﻿Public Class LOCATIONF
    Dim connect As CONDB = CONDB.NewConnection()
    'Dim connectlocal As conlocal = conlocal.NewConnection
    Dim PROVIDER_MASLOCATIONF As New PROVIDERSCLASS

    Private Sub LOCATIONF_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        SelectDatagridLocationf()

        DesignForm(Me)
        DesignGrid(maslocationfGrid)

        PROVIDER_MASLOCATIONF.GETHOSEM(CInt(main.txtUserRequest.Text.Trim), Convert.ToString(Me.Tag))
    End Sub

    Private Sub SelectDatagridLocationf()
        Dim objSelectDataMASLOCATIONF As New maslocationf
        Dim MASLOCATIONF As DataTable
        MASLOCATIONF = connect.GetTable(objSelectDataMASLOCATIONF.selectMaslocationf_)
        maslocationfGrid.PrimaryGrid.DataSource = MASLOCATIONF
    End Sub

    Private Sub maslocationfGrid_CellClick(sender As Object, e As DevComponents.DotNetBar.SuperGrid.GridCellClickEventArgs) Handles maslocationfGrid.CellClick
        Dim grid As DevComponents.DotNetBar.SuperGrid.GridRow
        grid = e.GridPanel.ActiveRow
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสสถานที่เก็บแฟ้ม").Value() IsNot DBNull.Value Then
            locationfIDTextbox.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("รหัสสถานที่เก็บแฟ้ม").Value()
        Else
            locationfIDTextbox.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานที่").Value() IsNot DBNull.Value Then
            locationfnameTextbox.Text = CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานที่").Value()
        Else
            locationfnameTextbox.Text = ""
        End If
        If CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value() = True Then
            locationfstatusCheckbox.Checked = True
        Else
            locationfstatusCheckbox.Checked = False
        End If
        connect = CONDB.NewConnection()
        If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
            Try
                Dim Sql As String
                connect.BeginTrans()
                Sql = "UPDATE maslocationf SET "
                If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
                    Sql += "`status` = 1 "
                Else
                    Sql += "`status` = 0 "
                End If
                Sql += "WHERE `location` = '" & locationfIDTextbox.Text & "' ;"
                connect.ExecuteNonQuery(Sql)
                connect.CommitTrans()
            Catch ex As Exception
                connect.RollbackTrans()
                MsgBox(ex.ToString)
            End Try
        End If
        connect.Dispose()
        'connectlocal = conlocal.NewConnection()
        'If e.GridCell.GridColumn.Name = "สถานะการเปิดใช้งาน" Then
        '    Try
        '        Dim Sql As String
        '        connectlocal.BeginTrans()
        '        Sql = "UPDATE MASFILELOCATION SET "
        '        If Convert.ToBoolean(CType(e.GridPanel.ActiveRow, DevComponents.DotNetBar.SuperGrid.GridRow).Cells("สถานะการเปิดใช้งาน").Value()) = True Then
        '            Sql += "[STATUS] = 1 "
        '        Else
        '            Sql += "[STATUS] = 0 "
        '        End If
        '        Sql += "WHERE [IDFILE] = '" & locationfIDTextbox.Text & "' ;"

        '        'connectlocal.ExecuteNonQuery(Sql)
        '        connectlocal.CommitTrans()
        '    Catch ex As Exception
        '        connectlocal.RollbackTrans()
        '        MsgBox(ex.ToString)
        '    End Try
        'End If
        'connectlocal.Dispose()
        addMaslocationf.Enabled = False
    End Sub

    Private Sub addMaslocationf_Click(sender As Object, e As EventArgs) Handles addMaslocationf.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_MASLOCATIONF.PADD_ = True Then
                Dim objInsertData As New maslocationf
                objInsertData.maslocationfName_ = locationfnameTextbox.Text
                objInsertData.maslocationfStatus_ = locationfstatusCheckbox.Checked
                objInsertData.insertMaslocationfData()

                SelectDatagridLocationf()

                locationfIDTextbox.Text = ""
                locationfnameTextbox.Text = ""
                locationfstatusCheckbox.Checked = False
            Else
                MsgBox(PROVIDER_MASLOCATIONF.PADDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub editMaslocationf_Click(sender As Object, e As EventArgs) Handles editMaslocationf.Click
        If main.PROVIDERPOLICIES.checklogin_user_ = True Then
            If PROVIDER_MASLOCATIONF.PUPD_ = True Then
                Dim editStat As Integer
                editStat = MsgBox("ท่านต้องการแก้ไขข้อมูลตำแหน่งดังกล่าวใช่หรือไม่", MsgBoxStyle.OkCancel)

                If editStat = 1 Then
                    Dim objEditData As New maslocationf
                    objEditData.maslocationfID_ = CInt(locationfIDTextbox.Text)
                    objEditData.maslocationfName_ = locationfnameTextbox.Text
                    objEditData.maslocationfStatus_ = locationfstatusCheckbox.Checked
                    objEditData.updateMaslocationfData()

                    SelectDatagridLocationf()

                    locationfIDTextbox.Text = ""
                    locationfnameTextbox.Text = ""
                    locationfstatusCheckbox.Checked = False
                End If
                addMaslocationf.Enabled = True
            Else
                MsgBox(PROVIDER_MASLOCATIONF.PUPDMSG_)
            End If
        Else
            TOASTCLASS.gloadToastMSG(Me, main.PROVIDERPOLICIES.LOGINUSERMSG_)
            main.txtUserRequest.Focus()
        End If
    End Sub

    Private Sub importExel_Click(sender As Object, e As EventArgs) Handles importExel.Click
        Dim nextform As New IMPORTEXCEL(maslocationf.Text)
        nextform.ShowDialog()
    End Sub

    Private Sub ButtonItem1_Click(sender As Object, e As EventArgs) Handles ButtonItem1.Click
        Dim nextform As New IMPORTEXCEL(maslocationf.Text)
        nextform.ShowDialog()
    End Sub
End Class